import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],

  // 配置代理和地址等
  server: {
    host: true,
    port: 9002,
    cors: true, // 允许跨域
    hmr: true, // 开启热更新
    proxy: {
      // 配置多个代理 只会在开发环境生效
      '/api': {
        target: 'https://10tl4sk847609.vicp.fun',
        changeOrigin: true, ///设置访问目标地址允许跨域
        rewrite: (p) => p.replace(/^\/api/, ''),
      },
      // '/api': {
      //   target: 'http://10.202.1.9:20038',
      //   changeOrigin: true, ///设置访问目标地址允许跨域
      //   rewrite: (p) => p.replace(/^\/api/, ''),
      // },
      // '/api': {
      //   target: 'http://127.0.0.1:8099',
      //   changeOrigin: true, ///设置访问目标地址允许跨域
      //   rewrite: (p) => p.replace(/^\/api/, ''),
      // },
    },
  },

  // 配置别名地址响应
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'), // 配置仓库别名路径
      '@store': path.resolve(__dirname, 'src/store/mainStore.js'),
    },
    extensions: ['.js', '.vue', '.css'],
  },

  publicDir: false, // 不生成public文件夹中的内容

  base: './', // 配置打包时的目录
})
